/*
 * Copyright 2005-2013 finalist.cn. All rights reserved.
 * Support: http://www.finalist.cn
 * License: http://www.finalist.cn/license
 */
package com.webapp.dao;

import java.util.List;


import org.springframework.stereotype.Repository;

import com.webapp.entity.Area;


/**
 * Dao - 地区
 * 
 * @author Finalist IT Group
 * @version 3.0
 */
@Repository("areaDao")
public class AreaDao extends AbstractDao<Area> {

	public List<Area> findRoots(Integer count) {
		String jpql = " where area.parent is null order by area.createdAt asc";
		/*TypedQuery<Area> query = entityManager.createQuery(jpql, Area.class).setFlushMode(FlushModeType.COMMIT);
		if (count != null) {
			query.setMaxResults(count);
		}*/
		
		return find(jpql);
	}

	public List<Area> findChildrens(Long parentId) {
		String jpql = " where area.parent.id = " +  parentId.toString() + " order by area.id asc";
		//TypedQuery<Area> query = entityManager.createQuery(jpql, Area.class).setFlushMode(FlushModeType.COMMIT).setParameter("parentId", parentId);
		
		return find(jpql);
	}
	
	public Area getAreaByCode(String code) {
		return get(" where area.co  = ? ", code);
	}
	public Area getAreaByName(String name) {
		return get(" where area.name  = ? ", name);
	}
	
}